﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.InteropServices;

namespace BDSim
{
    /// <summary>
    /// 空间段模型类别
    /// </summary>
    public enum ESpaceType
    {
        /// <summary>
        /// 星座
        /// </summary>
        Constellation,
        /// <summary>
        /// 卫星
        /// </summary>
        Satellite,
    }

    /// <summary>
    /// BD频点
    /// </summary>
    public class BD_Freq
    {
        private double _B1 = 1561.098;
        private double _B2 = 1207.14;
        private double _B3 = 1268.52;

        [Browsable(true), CategoryAttribute("信号频率"), DescriptionAttribute("信号频率1，单位为MHz")]
        public double B1
        {
            get { return _B1; }
            set { _B1 = value; }
        }

        [Browsable(true), CategoryAttribute("信号频率"), DescriptionAttribute("信号频率2，单位为MHz")]
        public double B2
        {
            get { return _B2; }
            set { _B2 = value; }
        }
        //频率3；
        [Browsable(true), CategoryAttribute("信号频率"), DescriptionAttribute("信号频率3，单位为MHz")]
        public double B3
        {
            get { return _B3; }
            set { _B3 = value; }
        }

        public override string ToString()
        {
            return string.Empty;
        }
    }

    /// <summary>
    /// GPS频点
    /// </summary>
    public class GPS_Freq
    {
        private double _L1 = 1575.42;
        private double _L2 = 1227.6;
        private double _L5 = 1176.45;

        [CategoryAttribute("信号频率"), DescriptionAttribute("信号频率1，单位为MHz")]
        public double L1
        {
            get { return _L1; }
            set { _L1 = value; }
        }

        [CategoryAttribute("信号频率"), DescriptionAttribute("信号频率2，单位为MHz")]
        public double L2
        {
            get { return _L2; }
            set { _L2 = value; }
        }
        //频率3；
        [CategoryAttribute("信号频率"), DescriptionAttribute("信号频率3，单位为MHz")]
        public double L5
        {
            get { return _L5; }
            set { _L5 = value; }
        }

        public override string ToString()
        {
            return string.Empty;
        }
    }

    /// <summary>
    /// GLONASS频点
    /// </summary>
    public class GLONASS_Freq
    {
        private double _L1 = 1602;
        private double _L2 = 1246;

        [CategoryAttribute("信号频率"), DescriptionAttribute("信号频率1，单位为MHz,1602+k*9116MHz,默认k=0")]
        public double L1
        {
            get { return _L1; }
            set { _L1 = value; }
        }

        [CategoryAttribute("信号频率"), DescriptionAttribute("信号频率2，单位为MHz,1246+k*716MHz,默认k=0")]
        public double L2
        {
            get { return _L2; }
            set { _L2 = value; }
        }

        public override string ToString()
        {
            return string.Empty;
        }
    }

    /// <summary>
    /// GALILEO系统频点
    /// </summary>
    public class GALILEO_Freq
    {
        private double _E1 = 1575.42;
        private double _E5a = 1176.45;

        [CategoryAttribute("信号频率"), DescriptionAttribute("信号频率1，单位为MHz")]
        public double E1
        {
            get { return _E1; }
            set { _E1 = value; }
        }

        [CategoryAttribute("信号频率"), DescriptionAttribute("信号频率2，单位为MHz")]
        public double E5a
        {
            get { return _E5a; }
            set { _E5a = value; }
        }
        public override string ToString()
        {
            return string.Empty;
        }
    }

    /// <summary>
    /// 星座特性参数
    /// </summary>
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class ConstellationFeatures
    {
        #region 字段

        private Constellation _parent;


        private EConstellationType _ConstellationType = EConstellationType.BD;
        private BD_Freq _BDFreq = new BD_Freq();
        private GPS_Freq _GPSFreq = new GPS_Freq();
        private GLONASS_Freq _GLOFreq = new GLONASS_Freq();
        private GALILEO_Freq _GalFreq = new GALILEO_Freq();
        private double _NavMsgUpdateFrequency;

        #endregion

        #region 属性
        /// <summary>
        /// 属于哪个星座的参数
        /// </summary>
        [XmlIgnore, Browsable(false)]
        public Constellation Parent
        {
            get { return _parent; }
            set { _parent = value; }
        }

        /// <summary>
        ///星座类型
        /// </summary>
        [PropertyOrder(1), Browsable(true), DescriptionAttribute(" 星座类型")]
        public EConstellationType ConstellationType
        {
            get { return _ConstellationType; }
            set
            {
                _ConstellationType = value;
                switch (_ConstellationType)
                {
                    case EConstellationType.BD:
                        PropertyFieldControl.SetPropertyVisibility(this, "BDFreq", true);
                        PropertyFieldControl.SetPropertyVisibility(this, "GPSFreq", false);
                        PropertyFieldControl.SetPropertyVisibility(this, "GLOFreq", false);
                        PropertyFieldControl.SetPropertyVisibility(this, "GalFreq", false);
                        break;
                    case EConstellationType.GPS:
                        PropertyFieldControl.SetPropertyVisibility(this, "BDFreq", false);
                        PropertyFieldControl.SetPropertyVisibility(this, "GPSFreq", true);
                        PropertyFieldControl.SetPropertyVisibility(this, "GLOFreq", false);
                        PropertyFieldControl.SetPropertyVisibility(this, "GalFreq", false);
                        break;
                    case EConstellationType.GLONASS:
                        PropertyFieldControl.SetPropertyVisibility(this, "BDFreq", false);
                        PropertyFieldControl.SetPropertyVisibility(this, "GPSFreq", false);
                        PropertyFieldControl.SetPropertyVisibility(this, "GLOFreq", true);
                        PropertyFieldControl.SetPropertyVisibility(this, "GalFreq", false);
                        break;
                    case EConstellationType.GALILEO:
                        PropertyFieldControl.SetPropertyVisibility(this, "BDFreq", false);
                        PropertyFieldControl.SetPropertyVisibility(this, "GPSFreq", false);
                        PropertyFieldControl.SetPropertyVisibility(this, "GLOFreq", false);
                        PropertyFieldControl.SetPropertyVisibility(this, "GalFreq", true);
                        break;
                    default:
                        break;
                }
                BDSimObject.DisplayObjectProperty(Parent);
            }
        }

        /// <summary>
        /// BD系统的频点
        /// </summary>
        [PropertyOrder(2), Browsable(true), DescriptionAttribute(" BD系统的频点"), TypeConverter(typeof(PropertySorter))]
        public BD_Freq BDFreq
        {
            get { return _BDFreq; }
            set { _BDFreq = value; }
        }

        /// <summary>
        /// GPS系统的频点
        /// </summary>
        [PropertyOrder(2), Browsable(false), DescriptionAttribute(" GPS系统的频点"), TypeConverter(typeof(PropertySorter))]
        public GPS_Freq GPSFreq
        {
            get { return _GPSFreq; }
            set { _GPSFreq = value; }
        }

        /// <summary>
        /// GLONASS系统的频点
        /// </summary>
        [PropertyOrder(2), Browsable(false), DescriptionAttribute(" GLONASS系统的频点"), TypeConverter(typeof(PropertySorter))]
        public GLONASS_Freq GLOFreq
        {
            get { return _GLOFreq; }
            set { _GLOFreq = value; }
        }

        /// <summary>
        /// GALILEO系统的频点
        /// </summary>
        [PropertyOrder(2), Browsable(false), DescriptionAttribute(" GALILEO系统的频点"), TypeConverter(typeof(PropertySorter))]
        public GALILEO_Freq GalFreq
        {
            get { return _GalFreq; }
            set { _GalFreq = value; }
        }

        /// <summary>
        /// 导航电文更新频率，单位为秒（s）
        /// </summary>
        [PropertyOrder(3), Browsable(false), DescriptionAttribute("导航电文更新频率，单位为秒（s）")]
        public double NavMsgUpdateFrequency
        {
            get { return _NavMsgUpdateFrequency; }
            set { _NavMsgUpdateFrequency = value; }
        }

        #endregion

        public override string ToString()
        {
            return string.Empty;
        }

    }

    /// <summary>
    /// Walker星座参数
    /// </summary>
    public class WalkerParam
    {
        private int _T;
        private int _P;
        private int _F;

        /// <summary>
        /// 卫星总数
        /// </summary>
        public int T
        {
            get { return _T; }
            set { _T = value; }
        }

        /// <summary>
        /// 轨道面个数
        /// </summary>
        public int P
        {
            get { return _P; }
            set { _P = value; }
        }

        /// <summary>
        /// 相位参数
        /// </summary>
        public int F
        {
            get { return _F; }
            set { _F = value; }
        }

    }


    /// <summary>
    /// 轨道仿真数据
    /// </summary>
    public struct OrbitSimData
    {
        public int ID;
        public string Name;
        public NodePosVel SatPV_ECI;
        //  public NodePosVel SatPV_ECF;
    }

    /// <summary>
    /// 星座生成输入参数1
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct ConstGenInput
    {
        /// <summary>
        /// 种子卫星位置、速度
        /// </summary>
        public NodePosVel OrbitPV;
    }

    /// <summary>
    /// 星座生成输入参数2
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct ConstGenParam
    {
        /// <summary>
        /// 卫星总数
        /// </summary>
        public int T;

        /// <summary>
        /// 轨道面个数
        /// </summary>
        public int P;

        /// <summary>
        /// 相位参数
        /// </summary>
        public int F;
    };

    /// <summary>
    /// 星座生成输出信息
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct ConstGenOutput
    {
        /// <summary>
        /// 星座卫星位置速度信息集
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 60)]
        public NodePosVel[] SatPV;

        /// <summary>
        /// 星座轨道位置速度信息集
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 360)]
        public NodePosVel[] OrbitPV;
    }
    

    /// <summary>
    /// 定义一个时隙内一条链路的测量规划
    /// </summary>
    public struct Linkpair
    {
        /// <summary>
        ///该时隙内发射卫星编号 
        /// </summary>
        public int SndID;

        /// <summary>
        /// 该时隙内接收卫星编号
        /// </summary>
        public int RecID;
    }
}
